<?php require_once 'header.php';?>    
<!-- DataTables Responsive CSS -->
    <link href="sb2/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <?php echo XXF_LNAME?><br>
                            <div style="border: 1px black solid;padding:3px;">
                                考试名称：<input type="text" id="kname">
                                当前学期：
                                <select id="term">
                                	<option value="0">请选择</option>
                                	<?php foreach (explode(",",gconf("web", "term")) as $v){?>
                                		<option><?php echo $v?></option>
                                	<?php }?>
                                </select>
                                <input type="button" value="增加" id="add" onclick="add()"> | 
                                <input type="button" value="全部等待" onclick="jihuo(0)">
                            </div>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>考试名称</th>
                                        <th>学期</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	<?php
                                	$i=0;
                                	foreach ($result as $row){$i++;
                                	?>
                                    <tr class="<?php echo $i%2==0?"even":"odd";?> gradeA">
                                    	<td><?php echo $i;?></td>
                                        <td><a href="kaoshiset/type/tongji/id/<?php echo $row['id']?>"><?php echo $row['kname']?></a></td>
                                        <td><?php echo $row['term']?></td>
                                        <td><?php echo $row['status']?></td>
                                        <td><input type="button" value="激活" onclick="jihuo(<?php echo $row['id']?>)"> <input type="button" value="删除" onclick="del(<?php echo $row['id']?>)"></td>
                                    </tr>
                                	<?php 
                                	}
                                	?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
             </div>
        </div>
        <!-- /#page-wrapper -->
  </div>
        <!-- DataTables JavaScript -->
<?php require_once 'bottom.php';?>
    <script src="sb2/vendor/datatables/js/jquery.dataTables.js"></script>
    <script src="sb2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="sb2/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true,
            "aaSorting": [[ 0, "desc" ]],
            "aLengthMenu": [ 50, 25, 10, 1]
        });
    });
    function add(){
		$kname=$("#kname").val();
		$term=$("#term").val();
		if($kname.length<2||$term=="0"){
			$.xalert("请将信息填写完整！");
		}else{
			$.xpost("kaoshiset",{
				kname:$kname,
				term:$term,
				type:"add"
			},function(data){
				if(data==1){
					window.location.reload();
				}else{
					$.xloading(0);
					$.xalert(data);
				}
			});
		}
    }
    function del(id){
		$.xconfirm("删除后无法恢复，确定要删除此条记录么？",function(data){
 			if(data){
				$.xloading(1);
				$.xtodb("del","kaoshi",{},id,function(data){
					if(data==0){
						$.xloading(0);
						$.xalert("删除失败");
					}else{
						location.reload();
					}
				});
			} 
		});
    }
    function jihuo(id){
    	$.xpost("kaoshiset",{
			id:id,
			type:"jihuo"
		},function(data){
			if(data==1){
				window.location.reload();
			}else{
				$.xloading(0);
				$.xalert(data);
			}
		});
    }
    </script>